import socket

s = socket.socket()
host = 'g.cn'
post = 80
s.connect((host, post))
ip, port = s.getsockname()
print('本机ip 和 port {} {}'.format(ip, port))
http_request = 'GET / HTTP/1.1 \r\n host:{}\r\n\r\n'.format(host)
# request bytes
request = http_request.encode('utf-8')
print('请求', request)
s.send(request)
# response bytes
response = s.recv(1023)
print('响应', response)
print('响应的str格式', response.decode('utf-8'))

